package com.losdun.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.losdun.common.annotation.Log;
import com.losdun.common.core.controller.BaseController;
import com.losdun.common.core.domain.AjaxResult;
import com.losdun.common.enums.BusinessType;
import com.losdun.cms.domain.GuestMessage;
import com.losdun.cms.service.IGuestMessageService;
import com.losdun.common.utils.poi.ExcelUtil;
import com.losdun.common.core.page.TableDataInfo;

/**
 * 网站留言Controller
 * 
 * @author swordye
 * @date 2025-08-26
 */
@RestController
@RequestMapping("/cms/message")
public class GuestMessageController extends BaseController
{
    @Autowired
    private IGuestMessageService guestMessageService;

    /**
     * 查询网站留言列表
     */
    @PreAuthorize("@ss.hasPermi('cms:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(GuestMessage guestMessage)
    {
        startPage();
        List<GuestMessage> list = guestMessageService.selectGuestMessageList(guestMessage);
        return getDataTable(list);
    }

    /**
     * 导出网站留言列表
     */
    @PreAuthorize("@ss.hasPermi('cms:message:export')")
    @Log(title = "网站留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GuestMessage guestMessage)
    {
        List<GuestMessage> list = guestMessageService.selectGuestMessageList(guestMessage);
        ExcelUtil<GuestMessage> util = new ExcelUtil<GuestMessage>(GuestMessage.class);
        util.exportExcel(response, list, "网站留言数据");
    }

    /**
     * 获取网站留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(guestMessageService.selectGuestMessageById(id));
    }

    /**
     * 新增网站留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:add')")
    @Log(title = "网站留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GuestMessage guestMessage)
    {
        return toAjax(guestMessageService.insertGuestMessage(guestMessage));
    }

    /**
     * 修改网站留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:edit')")
    @Log(title = "网站留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GuestMessage guestMessage)
    {
        return toAjax(guestMessageService.updateGuestMessage(guestMessage));
    }

    /**
     * 删除网站留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:remove')")
    @Log(title = "网站留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(guestMessageService.deleteGuestMessageByIds(ids));
    }
}
